package service

import (
	"context"
	__ "member_srv/basic/proto"
	"member_srv/handler/model"
)

type Server struct {
	__.UnimplementedMemberServer
}

func (s *Server) CreateUser(_ context.Context, in *__.CreateUserReq) (*__.CreateUserResp, error) {

	var user model.Member

	user = model.Member{
		Mobile:   in.Mobile,
		Password: in.Password,
	}

	err := user.AddMember()
	if err != nil {
		return nil, err
	}

	return &__.CreateUserResp{UserId: int64(user.Id)}, nil
}

func (s *Server) AddVideo(_ context.Context, in *__.AddVideoReq) (*__.AddVideoResp, error) {

	var video model.Video

	video = model.Video{
		Title:  in.Title,
		Info:   in.Info,
		Tag:    in.Tag,
		Level:  int8(in.Level),
		Image:  in.Image,
		Status: 0,
	}

	err := video.AddVideo()
	if err != nil {
		return nil, err
	}

	return &__.AddVideoResp{VideoId: int64(video.Id)}, nil
}
